package o;

import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class edp {
    private static final Object ˏ = new Object();
    private static edp ॱ = null;
    private SessionDownloadTask ˋ = null;
    private List<SessionDownloadTask> ˎ = new ArrayList();

    public static class d {
        private long ˊ;
        private double ˎ;
        private long ॱ;

        public long ˎ() {
            return this.ॱ;
        }

        public void ॱ(long j) {
            this.ॱ = j;
        }

        public long ˏ() {
            return this.ˊ;
        }

        public void ˋ(long j) {
            this.ˊ = j;
        }

        public double ˋ() {
            return this.ˎ;
        }

        public void ॱ(double d) {
            this.ˎ = d;
        }
    }

    public static edp ˏ() {
        edp o_edp;
        synchronized (ˏ) {
            if (ॱ == null) {
                ॱ = new edp();
            }
            o_edp = ॱ;
        }
        return o_edp;
    }

    public static int ˊ() {
        d ˋ = ˋ(new d());
        try {
            Thread.sleep(360);
        } catch (InterruptedException e) {
            Logger.e("PreDownloadTaskManager", "cpuUsage() " + e.toString());
        }
        return (int) Math.round(ˋ(ˋ).ˋ());
    }

    private static d ˋ(d dVar) {
        FileInputStream fileInputStream;
        InputStreamReader inputStreamReader;
        Exception e;
        BufferedReader bufferedReader;
        Throwable th;
        InputStreamReader inputStreamReader2 = null;
        BufferedReader bufferedReader2;
        try {
            fileInputStream = new FileInputStream("/proc/stat");
            try {
                inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
                try {
                    bufferedReader2 = new BufferedReader(inputStreamReader, 1000);
                    try {
                        String ॱ = doa.ॱ(bufferedReader2, 8192);
                        if (ॱ != null) {
                            String[] split = ॱ.split(HwAccountConstants.BLANK);
                            long parseLong = (Long.parseLong(split[2]) + Long.parseLong(split[3])) + Long.parseLong(split[4]);
                            long parseLong2 = Long.parseLong(split[5]);
                            dVar.ॱ((double) ((((float) (parseLong - dVar.ˎ())) * 100.0f) / ((float) (((parseLong - dVar.ˎ()) + parseLong2) - dVar.ˏ()))));
                            dVar.ॱ(parseLong);
                            dVar.ˋ(parseLong2);
                        }
                        if (bufferedReader2 != null) {
                            try {
                                bufferedReader2.close();
                            } catch (IOException e2) {
                                Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e2.toString());
                            }
                        }
                        if (inputStreamReader != null) {
                            try {
                                inputStreamReader.close();
                            } catch (IOException e22) {
                                Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e22.toString());
                            }
                        }
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException e222) {
                                Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e222.toString());
                            }
                        }
                    } catch (Exception e3) {
                        e = e3;
                        inputStreamReader2 = inputStreamReader;
                        bufferedReader = bufferedReader2;
                        try {
                            Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e.toString());
                            if (bufferedReader != null) {
                                try {
                                    bufferedReader.close();
                                } catch (IOException e2222) {
                                    Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e2222.toString());
                                }
                            }
                            if (inputStreamReader2 != null) {
                                try {
                                    inputStreamReader2.close();
                                } catch (IOException e22222) {
                                    Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e22222.toString());
                                }
                            }
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e222222) {
                                    Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e222222.toString());
                                }
                            }
                            return dVar;
                        } catch (Throwable th2) {
                            th = th2;
                            bufferedReader2 = bufferedReader;
                            inputStreamReader = inputStreamReader2;
                            if (bufferedReader2 != null) {
                                try {
                                    bufferedReader2.close();
                                } catch (IOException e4) {
                                    Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e4.toString());
                                }
                            }
                            if (inputStreamReader != null) {
                                try {
                                    inputStreamReader.close();
                                } catch (IOException e42) {
                                    Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e42.toString());
                                }
                            }
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e5) {
                                    Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e5.toString());
                                }
                            }
                            throw th;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        if (bufferedReader2 != null) {
                            bufferedReader2.close();
                        }
                        if (inputStreamReader != null) {
                            inputStreamReader.close();
                        }
                        if (fileInputStream != null) {
                            fileInputStream.close();
                        }
                        throw th;
                    }
                } catch (Exception e6) {
                    e = e6;
                    InputStreamReader inputStreamReader3 = inputStreamReader;
                    bufferedReader = null;
                    inputStreamReader2 = inputStreamReader3;
                    Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e.toString());
                    if (bufferedReader != null) {
                        bufferedReader.close();
                    }
                    if (inputStreamReader2 != null) {
                        inputStreamReader2.close();
                    }
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                    return dVar;
                } catch (Throwable th4) {
                    th = th4;
                    bufferedReader2 = null;
                    if (bufferedReader2 != null) {
                        bufferedReader2.close();
                    }
                    if (inputStreamReader != null) {
                        inputStreamReader.close();
                    }
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                    throw th;
                }
            } catch (Exception e7) {
                e = e7;
                bufferedReader = null;
                Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e.toString());
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
                if (inputStreamReader2 != null) {
                    inputStreamReader2.close();
                }
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                return dVar;
            } catch (Throwable th5) {
                th = th5;
                inputStreamReader = null;
                bufferedReader2 = null;
                if (bufferedReader2 != null) {
                    bufferedReader2.close();
                }
                if (inputStreamReader != null) {
                    inputStreamReader.close();
                }
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                throw th;
            }
        } catch (Exception e8) {
            e = e8;
            fileInputStream = null;
            bufferedReader = null;
            Logger.e("PreDownloadTaskManager", "readUsage(CpuMessage msg) " + e.toString());
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            if (inputStreamReader2 != null) {
                inputStreamReader2.close();
            }
            if (fileInputStream != null) {
                fileInputStream.close();
            }
            return dVar;
        } catch (Throwable th6) {
            th = th6;
            fileInputStream = null;
            inputStreamReader = null;
            bufferedReader2 = null;
            if (bufferedReader2 != null) {
                bufferedReader2.close();
            }
            if (inputStreamReader != null) {
                inputStreamReader.close();
            }
            if (fileInputStream != null) {
                fileInputStream.close();
            }
            throw th;
        }
        return dVar;
    }

    public synchronized SessionDownloadTask ˊ(String str) {
        SessionDownloadTask sessionDownloadTask;
        for (SessionDownloadTask sessionDownloadTask2 : ˋ()) {
            if (sessionDownloadTask2.ˊˊ().equals(str)) {
                break;
            }
        }
        sessionDownloadTask2 = null;
        return sessionDownloadTask2;
    }

    public SessionDownloadTask ˎ() {
        return this.ˋ;
    }

    public void ˎ(SessionDownloadTask sessionDownloadTask) {
        this.ˋ = sessionDownloadTask;
    }

    public List<SessionDownloadTask> ˋ() {
        return this.ˎ;
    }
}
